<?php
//Needed for connectDB
require("dbFunctions.php");

/**
 * Removes the associations between a container and specific items within it.
 * 
 * Author: Steve Gennaoui
 * Date: 11/07/2012
 */

//Get parameters
$container_id = $_REQUEST['container_id'];
$json_contained_items_to_remove = $_REQUEST['items_to_remove'];

//Get an array of the item ids to disassociate from the container
$items_to_remove = json_decode( $json_contained_items_to_remove );

if( !idIsValid($container_id,"QR_Code") )
	die("The Container ID $container_id is invalid.");

$dbh = connectDB();

foreach($items_to_remove as $id)
{
	if( idIsValid($id,"QR_Code") )
	{
		$query = "DELETE FROM Resource_Packages WHERE container_qr_code=:container AND contained_qr_code=:contained";
		$stmt = $dbh->prepare($query);
		$stmt->bindParam(':container',$container_id);
		$stmt->bindParam(':contained',$id);
		$stmt->execute();
	}
}

$stmt = null;
$dbh = null;
?>
